package com.xiaotu.spring.config;

import com.xiaotu.spring.service.BeanE;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author zhangxiao
 * @create 2021-11-11 17:23
 */
@Slf4j
@Component
public class TestBeanPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof BeanE) {
            log.info("BeanPostProcessor...postProcessBeforeInitialization");
            System.out.println(bean);
            ((BeanE) bean).setName("李四");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof BeanE) {
            log.info("BeanPostProcessor...postProcessAfterInitialization");
            System.out.println(bean);
        }
        return bean;
    }
}
